package System;

//判断下面两种方法的效率，判断水仙花数
public class systemtext2 {
    public static void main(String[] args) {
        long l = System.currentTimeMillis();
        int count = 0;
        for (int i = 1; i < 100000; i++) {
            if (zishu1(i) == true) {
                count++;
            }

            /*if (zishu(i) == true) {
                count++;
            }*/
        }
        long l1 = System.currentTimeMillis();
        System.out.println("1-10000之间有"+count+"个水仙花数");
        System.out.println("方法一用时为："+(l1-l));
    }

    //方法一
    private static boolean zishu(int a) {
        for (int i = 2; i < a; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    //方法二，这个效率更高
    private static boolean zishu1(int a) {
        for (int i = 2; i <= Math.sqrt(a); i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }
}
